<%@ page import="org.jsecurity.web.filter.authc.FormAuthenticationFilter" %>
<%@include file="/WEB-INF/pages/commons/commons.jsp" %>

<stripes:layout-render name="${_themePath}/basic-layout-without-navbar.jsp" _title="View User">
    <stripes:layout-component name="_head">
        <script type="text/javascript">
            // === _userHeaderMenu
                YAHOO.util.Event.onContentReady("_userHeaderMenu", function() {
                    var _manageHeaderMenu = new YAHOO.widget.Button("_userHeaderMenuButton",
                                            { type: "menu", menu: "_userHeaderMenuButtonSelect" });
                    //	"click" event listener for the second Button's Menu instance
                    var onMenuClick = function (p_sType, p_aArgs) {
                        var oEvent = p_aArgs[0];	//	DOM event
                        var oMenuItem = p_aArgs[1];	//	MenuItem instance that was the
                                                    //	target of the event
                        if (oMenuItem) {
                            if ('0' == oMenuItem.value) {   // delete user
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.user.RemoveUserActionBean" event="remove">
                                        <stripes:param name="user" value="${actionBean.user.id}"/>
                                </stripes:url>
                                document.location.href = '${url}';
                            }
                            else if ('1' == oMenuItem.value) { // edit user
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.user.EditUserActionBean" event="view">
                                    <stripes:param name="user" value="${actionBean.user.id}"/>
                                </stripes:url>
                                document.location.href = '${url}';
                            }
                            else {
                                alert('unrecognized menu option');
                            }
                        }
                    };
                    //	Add a "click" event listener for the Button's Menu
                    _manageHeaderMenu.getMenu().subscribe("click", onMenuClick);
                });
        </script>
    </stripes:layout-component>



    <stripes:layout-component name="_topNav">
        <H1>View User</H1>
        <UL class="gc-topnav-tabs">
            <LI>
                <span id="_userHeaderMenu">
                <input type="button" id="_userHeaderMenuButton" value="Options"/>
                <select id="_userHeaderMenuButtonSelect">
                    <jsecurity:hasPermission name="user:remove:${actionBean.user.id}">
                        <option value="0">Delete User</option>
                        <option value="x">&nbsp;</option>
                    </jsecurity:hasPermission>
                    <jsecurity:hasPermission name="user:edit:${actionBean.user.id}">
                        <option value="1">Edit User</option>
                    </jsecurity:hasPermission>
                </select>
                </span>
            </LI>
        </UL>
    </stripes:layout-component>

    <stripes:layout-component name="_content">
        <h2>Description [<a id="_hideDescription" href="#">Hide</a>/<a id="_showDescription" href="#">Show]</a></h2>
        <div id="_description">
        <p>
            This page display the profile of this user (${actionBean.user.username}). The username is not alterable
            upon creation. The email address is alterable but mandatory.
        </p>
        <p>
            <h3>Disabling/Locking</h3>
            Disable and lock perform
            the same functionality here. I'm not sure why I came up with both at the first place. Perhaps one
            shall be removed latter on. Once a user is being locked/disabled he will no longer be able to logged
            in as the account however all the changes and alteration that the user has done is preserved. Almost
            all of the time you'd want to disable/lock a user instead of deleting them. :-)
        </p>
        <p>
            <h3>Expiry Date</h3>
            You could also set a future date whereby this account will no longer be active i.e. locked/disabled.
        </p>
        <p>
            <h3>Roles</h3>
            Following are the roles available. Normally the default role will suffice, if however for some reason
            you've decided to change some of the roles of a particular users, be sure you know what you are doing.
            Consider youself WARNED. :-)
            <ul>
            <li><b>Anonymous</b>
            Anonymous user could view but cannot edit any space, page or comments. However he could nether view
            the available users profile nor edit them. Visitors that have not sign in or registered with the system
            will have this role.</li>
            <li><b>Registered User</b>
            Any user that is registered with FooBarWiki will be a registered user. They could view, edit and comment
            on any pages in any space, this include adding pages to any spaces. But only deleting page, spaces and
            comments that he originally created.</li>
            <li><b>Moderator</b>
            User with this role and is a member of a space or spaces will be able to remove any spaces, page or
            comments even if he's not the original creator. Any user that registered with FooBarWiki will automatically
            have this role. However this role will not take effect unless this user is being specifically assigned
            as the member of a particular space.</li>
            <li><b>Administrator</b>
            The GOD of FooBarWiki. Any user with this role will be able to do anything / everything.
            </li>
            </ul>
        </p>
        <p/>
        <p/>
        <p/>
        </div>

        <h2>User ${actionBean.user.username}'s details</h2>
        <stripes:messages/>
        <stripes:errors/>
        <jsecurity:hasPermission name="user:view:${actionBean.user.id}">
        <stripes:form beanclass="foo.bar.wiki.web.action.user.EditUserActionBean" method="POST">
            <table width="100%">
            <tr>
                <td>Username:</td>
                <td><stripes:text name="user.username" value="${actionBean.user.username}" disabled="true"/></td>
            </tr>
            <tr>
                <td>Email: </td>
                <td><stripes:text name="user.email" value="${actionBean.user.email}" disabled="true"/></td>
            </tr>
            <tr>
                <td>Locked: </td>
                <td><stripes:checkbox name="user.locked" value="true" checked="${actionBean.user.locked}" disabled="true"/></td>
            </tr>
            <tr>
                <td>Disabled: </td>
                <td><stripes:checkbox name="user.disabled" value="true" checked="${actionBean.user.disabled}" disabled="true"/></td>
            </tr>
            <tr>
                <td>Expiry Date: </td>
                <td><fmt:formatDate var="theExpiryDate" value="${actionBean.user.expiryDate}" pattern="dd/MM/yyyy" />
                    <stripes:text name="user.expiryDate" value="${theExpiryDate}" disabled="true"/></td>
            </tr>
            <tr>
                <stripes:useActionBean var="utilitiesActionBean"
                               beanclass="foo.bar.wiki.web.action.general.UtilitiesActionBean"
                               executeResolution="false"
                               alwaysExecuteEvent="false"
                               event="roles" validate="false" />
                <td>Roles:</td>
                <td>
                    <c:forEach var="currentRole" varStatus="status" items="${utilitiesActionBean.roles}">
                        <stripes:checkbox name="roles" disabled="true" value="${stripes:enumName(currentRole)}"
                                          checked="${actionBean.user.roleTypes}" />
                        <fmt:message key="${stripes:enumName(currentRole)}" />
                        <br/>
                    </c:forEach>
                </td>
            </tr>
            </table>
        </stripes:form>
        </jsecurity:hasPermission>
        <jsecurity:lacksPermission name="user:view:${actionBean.user.id}">
            Lacks "user:view:${actionBean.user.id}" permissions
        </jsecurity:lacksPermission>
    </stripes:layout-component>

</stripes:layout-render>



